
// 1218.最长定差子序列
class Solution {
public:
    int longestSubsequence(vector<int>& arr, int difference) {
        // 哈希表 + DP实现

        int n = arr.size(), ret = 1;
        unordered_map<int,int> m;
        m.insert({arr[0] , 1});
        for(int i = 1; i < n ;i++)
        {
            m[arr[i]] = m[arr[i] - difference] + 1;
            ret = max(ret, m[arr[i]]);
        }
        return ret;
    }
};